var ipt=document.querySelectorAll("input")
/* 正则判断 */
var isname=0;
ipt[0].onkeyup=function(){
    var res=/^(\w|[\u2E80-\u9FFF]){3,6}$/.test(ipt[0].value);
    if(res){
        //判断用户名可用
        axios.get(isUsername,{params:{username:ipt[0].value}}).then(function(res){
            console.log(res.data);
            if(res.data.code==0){
                ipt[0].nextElementSibling.innerHTML=res.data.msg;
                 isname=0;
            }else{
                ipt[0].nextElementSibling.innerHTML=res.data.msg;
                isname=1;
            }
        })
        
    }else{
        ipt[0].nextElementSibling.innerHTML="格式错误";
        isname=0;
    }
}
var ispassword=0;
ipt[1].onkeyup=function(){
    var res=/^\w{6,12}$/.test(ipt[1].value);
    if(res){
        ipt[1].nextElementSibling.innerHTML="格式正确";
        ispassword=1;
    }else{
        ipt[1].nextElementSibling.innerHTML="格式错误";
        ispassword=0;
    }
}
var loginbtn=document.querySelector("button");
var msgMask=document.querySelector(".msgMask");
var msgbtn=document.querySelector(".msg button");
    loginbtn.onclick=function(){
        if(isname==1&&ispassword==1){
        console.log(11);
        var username=ipt[0].value;
        var password=ipt[1].value;
        axios.get(LoginApi,{params:{username,password}}).then(function(res){
            if(res.data.code==1){
                alert("注册成功");
                localStorage.setItem("username",JSON.stringify(ipt[0].value));
                localStorage.setItem("password",JSON.stringify(ipt[1].value));
                location.href="../html/home.html"
            }else{
                msgMask.style.display="block";
            }
        })
    }else{
        msgMask.style.display="block";
    }
}
msgbtn.onclick=function(){
    msgMask.style.display="none";
}